package cn.dapeng.utils;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * LinkedList 是链表结构 性能高
 * ArrayList 是数组结构  性能差
 */
public class LinkedListAndArrayListPerformance {

    public static void main(String[] args) {
        int testTimes = 1000000;
        long start, end;

        List<Integer> l1 = new ArrayList<>();
        start = System.currentTimeMillis();
        for (int i = 0; i < testTimes; i++) {
            l1.add(0, i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

        System.out.println(" ============================ ");

        List<Integer> l2 = new LinkedList<>();
        start = System.currentTimeMillis();
        for (int i = 0; i < testTimes; i++) {
            l2.add(0, i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}
